package m2dl.ter.mirrorgame;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ChangePlayer extends Activity {
	
	/** Gestures table handling*/
	final String EXTRA_GESTURES = "gestures";
	ArrayList<Integer> gesture_tab;
	
	/** Attributes buttons classes. */
	protected Button playGameButton;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_change_player);
		
		Intent intent = getIntent();
		
		if (intent != null){
			gesture_tab = intent.getIntegerArrayListExtra(EXTRA_GESTURES);
		} else {
			gesture_tab = new ArrayList<Integer>();
			gesture_tab.add(0);
			gesture_tab.add(2);
			gesture_tab.add(1);
			gesture_tab.add(0);
			gesture_tab.add(2);
			gesture_tab.add(3);
			gesture_tab.add(1);
			gesture_tab.add(3);
			gesture_tab.add(1);
			gesture_tab.add(0);
		}

		// Manages the playGameButton
		this.playGameButton = (Button) findViewById(R.id.id_change_player_play);
		this.playGameButton.setVisibility(View.VISIBLE);
		this.playGameButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ChangePlayer.this, Mirror.class);
				intent.putExtra(EXTRA_GESTURES, gesture_tab);
				startActivity(intent);
				System.exit(RESULT_OK);
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.change_player, menu);
		return true;
	}
	
	@Override
	public void onStop() {
		super.onStop();
		System.exit(RESULT_OK);
		this.finish();
	}

	// Manages the menu
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.change_player_quitter:
			finish();
			return true;
		}
		return false;
	}
}
